package com.example.administrator.nl;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.nl.activity.appointment.AppointmentActivity;
import com.example.administrator.nl.base.BaseActivity;
import com.example.administrator.nl.fragment.CartFragment;
import com.example.administrator.nl.fragment.HomeFragment;
import com.example.administrator.nl.fragment.MeFragment;
import com.example.administrator.nl.fragment.ShoppingFragment;
import com.example.administrator.nl.util.ViewPageFragmentAdapter;
import com.example.administrator.nl.view.MainViewPager;
import com.leaf.library.StatusBarUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.viewPager)
    MainViewPager viewPager;

    @BindView(R.id.rg_main)
    RadioGroup rg_main;

    @BindView(R.id.rb_home_main)
    RadioButton rb_home_main;

    @BindView(R.id.rb_shopping_main)
    RadioButton rb_shopping_main;

    @BindView(R.id.rb_cart_main)
    RadioButton rb_cart_main;

    @BindView(R.id.iv_appointment_main)
    ImageView iv_appointment_main;

    @BindView(R.id.tv_appointment_main)
    TextView tv_appointment_main;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void init() {
        tv_appointment_main.setOnClickListener(this);
        iv_appointment_main.setOnClickListener(this);
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new HomeFragment());
        fragments.add(new ShoppingFragment());
        fragments.add(new CartFragment());
        fragments.add(new MeFragment());

        viewPager.setAdapter(new ViewPageFragmentAdapter(getSupportFragmentManager(), fragments));
        viewPager.setOffscreenPageLimit(4);
        listener();
    }

    @Override
    public int getContentView() {
        return R.layout.activity_main;
    }

    private void listener() {
        rg_main.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (group.getCheckedRadioButtonId()) {
                    case R.id.rb_home_main:
                        viewPager.setCurrentItem(0);
                        break;
                    case R.id.rb_shopping_main:
                        viewPager.setCurrentItem(1);
                        break;
                    case R.id.rb_cart_main:
                        viewPager.setCurrentItem(2);
                        break;
                    case R.id.rb_me_main:
                        viewPager.setCurrentItem(3);
                        break;
                    default:
                        break;

                }
            }
        });


    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_appointment_main:
            case  R.id.tv_appointment_main:
                Intent intent = new Intent(MainActivity.this, AppointmentActivity.class);
                startActivity(intent);
                break;
        }
    }
}
